#include <iostream>
#include "sqlite.hpp"

int select_stu_callback(void* arg, int col_count, char** result, char** fields_name)
{
    //result表示的是某一行的数据
    for (int i = 0; i < col_count; i++)
    {
        std::cout << result[i] << " ";
    }
    std::cout << std::endl;

    return 0;  //非常重要，否则会发生错误
}

int main()
{
    //创建库文件
    SqliteHelper helper("./test.db");
    helper.open();
    //1.创建/打开表 （学生信息表：编号, 姓名，年龄）
    const char* ct = "create table if not exists student(id int primary key, name varchar(32), age int);";
    helper.exec(ct, nullptr, nullptr);  //创建表不需要回调函数
    //2.增删改查
    // const char* insert_sql1 = "insert into student values(1, '张三', 18);";
    // const char* insert_sql2 = "insert into student values(2, '李四', 20);";
    // const char* insert_sql3 = "insert into student values(3, '王五', 32);";
    // helper.exec(insert_sql1, nullptr, nullptr);
    // helper.exec(insert_sql2, nullptr, nullptr);
    // helper.exec(insert_sql3, nullptr, nullptr);

    // const char* update_sql = "delete from student where id = 2";
    // helper.exec(update_sql, nullptr, nullptr);

    const char* select_sql = "select * from student";
    helper.exec(select_sql, select_stu_callback, nullptr);

    //3.关闭数据库
    helper.close();

    return 0;
}